/******************************************************************
** This code is part of Breakout.
**
** Breakout is free software: you can redistribute it and/or modify
** it under the terms of the CC BY 4.0 license as published by
** Creative Commons, either version 4 of the License, or (at your
** option) any later version.
******************************************************************/
#include "ballobject.h"

BallObject::BallObject() 
    : GameObject(), Radius(0.0f) { }

BallObject::BallObject(b2World *world, glm::vec2 pos, GLfloat radius, Texture2D sprite)
    :  GameObject(), Radius(radius)
{
	mSprite = sprite;
	mSize = glm::vec2(radius * 2);

	b2BodyDef def;
	def.type = b2_dynamicBody;
	def.position.Set(pos.x, pos.y);
	mPhysicBody = world->CreateBody(&def);
	// set shape
	b2CircleShape shape;
	// shape.m_p.Set(ballPos.x, ballPos.y);
	shape.m_radius = radius;
	// define fixture
	b2FixtureDef fixDef;
	fixDef.shape = &shape;
	fixDef.density = 1.f;
	fixDef.friction = 0.f;

	mPhysicBody->CreateFixture(&fixDef);
	mPhysicBody->SetFixedRotation(true);

	mPhysicBody->SetUserData(this);
}


// Resets the ball to initial Stuck Position (if ball is outside window bounds)
void BallObject::Reset(b2Vec2 &position, b2Vec2 &velocity)const
{
	mPhysicBody->SetTransform(position, 0);
	mPhysicBody->SetLinearVelocity(velocity);
}